import { execSync } from 'child_process'
import { decode } from 'iconv-lite'

function ls() {
  // netsh interface portproxy show all
  const result = execSync('netsh interface portproxy show all', { encoding: 'buffer' })

  const data = decode(result, 'gbk')
  // 从第 5 行开始是数据
  const lines = data.split('\r\n').slice(5)
  // 去掉空行
  const list = lines.filter(Boolean).map(line => {
    const [listen, port, wslListen, wslPort] = line.split(/\s+/)
    return {
      '宿主机 ipv4': listen,
      宿主机端口: port,
      'wsl ipv4': wslListen,
      wsl端口: wslPort
    }
  })
  console.table(list)
}

ls()
